clear; close all; clc;

actionsFull = zeros(4000, 1);
moveRatingsFull = zeros(4000, 1);
piecesFull = zeros(4000, 1);
tablesFull = cell(4000, 1);

first = 1;

load games-miksa;

last = first + length(tables) - 1;

actionsFull(first : last) = actions;
moveRatingsFull(first : last) = moveRatings;
piecesFull(first : last) = pieces;
tablesFull(first : last) = tables;

first = last + 1;

clear actions moveRatings pieces tables;
load games-mihokovic;

last = first + length(tables) - 1;

actionsFull(first : last) = actions;
moveRatingsFull(first : last) = moveRatings;
piecesFull(first : last) = pieces;
tablesFull(first : last) = tables;

first = last + 1;

clear actions moveRatings pieces tables;
load games-marovic;

last = first + length(tables) - 1;

actionsFull(first : last) = actions;
moveRatingsFull(first : last) = moveRatings;
piecesFull(first : last) = pieces;
tablesFull(first : last) = tables;

first = last + 1;

clear actions moveRatings pieces tables;
load games-pribil;

last = first + length(tables) - 1;

actionsFull(first : last) = actions;
moveRatingsFull(first : last) = moveRatings;
piecesFull(first : last) = pieces;
tablesFull(first : last) = tables;

first = last + 1;

clear actions moveRatings pieces tables;
load games-miksa-begin;

last = first + length(tables) - 1;

actionsFull(first : last) = actions;
moveRatingsFull(first : last) = moveRatings;
piecesFull(first : last) = pieces;
tablesFull(first : last) = tables;

first = last + 1;

clear actions moveRatings pieces tables;
load games-mihokovic-begin;

last = first + length(tables) - 1;

actionsFull(first : last) = actions;
moveRatingsFull(first : last) = moveRatings;
piecesFull(first : last) = pieces;
tablesFull(first : last) = tables;

first = last + 1;

clear actions moveRatings pieces tables;
load games-pribil-begin;

last = first + length(tables) - 1;

actionsFull(first : last) = actions;
moveRatingsFull(first : last) = moveRatings;
piecesFull(first : last) = pieces;
tablesFull(first : last) = tables;

first = last + 1;

clear actions moveRatings pieces tables;
load games-marovic-begin;

last = first + length(tables) - 1;

actionsFull(first : last) = actions;
moveRatingsFull(first : last) = moveRatings;
piecesFull(first : last) = pieces;
tablesFull(first : last) = tables;

first = last + 1;

clear actions moveRatings pieces tables;

r = randperm(last);

actions = actionsFull(r);
moveRatings = moveRatingsFull(r);
pieces = piecesFull(r);
tables = tablesFull(r);

save games-all tables actions pieces moveRatings;


ind = find(moveRatings ~= 0);
actions = actions(ind);
moveRatings = moveRatings(ind);
pieces = pieces(ind);
tables = tables(ind);

save games-nonzeromove tables actions pieces moveRatings;
